layui.use(['layer', 'form', 'table', 'admin', 'ax', 'func'], function () {
    var $ = layui.$;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;

    /**
     *  订单列表
     */
    var orderTable = {
        tableId: "orderTable",
        userId: $('#userId').val()//表格id
    };

    /**
     * 初始化表格的列
     */
    orderTable.initColumn = function () {
        return [[
            {field: 'order_id', align: "center", sort: true, title: '订单编号'},
            {field: 'order_content', align: "center", sort: true, title: '订单内容'},
            {field: 'order_status_name', align: "center", sort: true, title: '订单状态'},
            {field: 'order_amount', align: "center", sort: true, title: '订单金额'},
            {field: 'created_at', align: "center", sort: true, title: '创建时间'}
        ]];
    };

    // 渲染表格
    table.render({
        elem: '#' + orderTable.tableId,
        url: Feng.ctxPath + '/order/list?userId=' + orderTable.userId,
        page: true,
        height: "full-98",
        cellMinWidth: 100,
        cols: orderTable.initColumn()
    });


    /**
     *   下级列表
     */
    var juniorTable = {
        tableId: "juniorTable",  //表格id
        userId: $('#userId').val()
    };

    /**
     * 初始化表格的列
     */
    juniorTable.initColumn = function () {
        return [[
            {field: 'company_name', align: "center", sort: true, title: '公司名称'},
            {field: 'user_name', align: "center", sort: true, title: '用户名称'},
            {field: 'logon_id', align: "center", sort: true, title: '手机号码'},
            {field: 'company_email', align: "center", sort: true, title: '邮箱'},
            {field: 'created_at', align: "center", sort: true, title: '注册时间'},
            {field: 'updated_at', align: "center", sort: true, title: '最近登录时间'},
            {field: 'user_role', align: "center", sort: true, title: '用户类型'}
        ]];
    };

    // 渲染表格
    table.render({
        elem: '#' + juniorTable.tableId,
        url: Feng.ctxPath + '/company/junior-list/' + juniorTable.userId,
        page: true,
        height: "full-98",
        cellMinWidth: 100,
        cols: juniorTable.initColumn(),
        done: function (res, curr, count) {
            //如果是异步请求数据方式，res即为你接口返回的信息。
            $("[data-field='user_role']").children().each(function () {
                if ($(this).text() == '2') {
                    $(this).text("员工")
                } else if ($(this).text() == '3') {
                    $(this).text("厂家")
                }
            });
        }
    });

});
